﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RailwayDAL;
using System.Collections.ObjectModel;
using RoutesAdministration.Commands;

namespace RoutesAdministration.ViewModels
{
    public class ViewModelMain:ViewModelBase
    {
        RailwayCompanyEntities dbEntity;
        private ObservableCollection<Station> stations;
        private ObservableCollection<Route> routes;
        private ObservableCollection<TravelTime> travelTimes;
        private ObservableCollection<RoutesStation> routesStations;

        public ObservableCollection<Station> Stations
        {
            get { return stations; }
            set 
            {
                if (this.stations != value)
                {
                    stations = value;
                    OnPropertyChanged("Stations");
                }
            }
        }

        public ObservableCollection<Route> Routes
        {
            get { return routes; }
            set
            {
                if (this.routes != value)
                {
                    routes = value;
                    OnPropertyChanged("Routes");
                }
            }
        }

        public ObservableCollection<TravelTime> TravelTimes
        {
            get { return travelTimes; }
            set
            {
                if (this.travelTimes != value)
                {
                    travelTimes = value;
                    OnPropertyChanged("Traveltimes");
                }
            }
        }

        public ObservableCollection<RoutesStation> RoutesStations
        {
            get { return routesStations; }
            set
            {
                if (this.routesStations != value)
                {
                    routesStations = value;
                    OnPropertyChanged("RoutesStations");
                }
            }
        }

        public RelayCommands SaveCommand
        {
            get
            {
                return new RelayCommands((p) => dbEntity.SaveChanges());
            }
        }

        public ViewModelMain()
        {
            dbEntity = new RailwayCompanyEntities();
            stations = new ObservableCollection<Station>(dbEntity.Stations);
            routes = new ObservableCollection<Route>(dbEntity.Routes);
            travelTimes = new ObservableCollection<TravelTime>(dbEntity.TravelTimes);
            routesStations = new ObservableCollection<RoutesStation>(dbEntity.RoutesStations);
        }
    }
}
